#ifndef TCPCLIENT_H_
#define TCPCLIENT_H_
#include <string>
#include <mutex>
#include <Afsocket.h>
#include "NetMgr.h"



using OnReadCallBack = std::function<void(int8_t*, int32_t)>;
class TcpClient
{
public:
	TcpClient();
	virtual ~TcpClient();

	virtual bool Connect(std::string ip, uint16_t port);

	virtual int SetCallBack(OnReadCallBack oOnReadCallBack)
	{
		m_OnReadCallBack = oOnReadCallBack;
		return 0;
	}

	virtual void OnRead();

	virtual int Send(char* data, int len);

	std::string GetIPAddress() const
	{
		return ip_;
	}

	uint16_t GetPort() const
	{
		return port_;
	}

protected:

	uint16_t port_;
	std::string ip_;
	bool is_started_=false;
	std::mutex mutex_;

	AfTcpSocket m_AfTcpSocket;


	std::vector<char> m_readBuffer;

	std::shared_ptr<WorkerThreadN> m_task_scheduler;

	OnReadCallBack m_OnReadCallBack;
};

#endif